#include "axpy_rvv.h"
//#include "omatcopy.h"
#include<stdio.h>
#include <iostream>
#include <chrono>

int main()
{
	const int len = 1920;
	const int num = 20000;
	float a[2]={0.25,0.5};
	
	float x1[len], y1[len], x2[len], y2[len], x3[len], y3[len];
	long long total_duration1 = 0;
	long long total_duration2 = 0;
	long long total_duration3 = 0;

	for(int i = 0;i<len;i++)
	{
		x1[i] = i + 1.5;
		x2[i] = i + 1.5;
		x3[i] = i + 1.5;
		y1[i] = i + 1.55;
		y2[i] = i + 1.55;
		y3[i] = i + 1.55;
	}

    std::cout<<std::endl<<"rvv1:\n";
	for(int i = 0;i<num;i++)
	{
 		// 开始计时
        auto start1 = std::chrono::high_resolution_clock::now();
        // 调用要测试的函数
        axpy_riscv1(x1, y1, len, a[0]);
        // 结束计时
        auto end1 = std::chrono::high_resolution_clock::now();
        // 计算执行时间
        auto duration1 = std::chrono::duration_cast<std::chrono::nanoseconds>(end1 - start1).count();
		total_duration1 +=duration1;
    	//std::cout << duration1 <<" ";
	}
	// 计算平均执行时间
    auto average_duration1 = total_duration1 / num;
	std::cout << "Average duration (nanoseconds): " << average_duration1 << std::endl;
	std::cout<<std::endl<<"rvv2：\n";
	for(int i = 0;i<num;i++)
	{
		// 开始计时
    	auto start2 = std::chrono::high_resolution_clock::now();
		//调用要测试的函数
    	axpy_riscv2(x3,y3,len,a[0]);
    	// 结束计时
    	auto end2 = std::chrono::high_resolution_clock::now();
    	// 计算执行时间
    	auto duration2 = std::chrono::duration_cast<std::chrono::nanoseconds>(end2 - start2).count();
		total_duration2 +=duration2;
    	// 输出执行时间
    	//std::cout << duration2 << " " ;
	}
	auto average_duration2 = total_duration2 / num;
	std::cout << "Average duration (nanoseconds): " << average_duration2 << std::endl;
    std::cout<<std::endl<<"axpy：\n";
	for(int i = 0;i<num;i++)
	{
		// 开始计时
    	auto start3 = std::chrono::high_resolution_clock::now();
		//调用要测试的函数
    	axpy(x3,y3,len,a[0]);
    	// 结束计时
    	auto end3 = std::chrono::high_resolution_clock::now();
    	// 计算执行时间
    	auto duration3 = std::chrono::duration_cast<std::chrono::nanoseconds>(end3 - start3).count();
		total_duration3 +=duration3;
    	// 输出执行时间
    	//std::cout << duration3 << " " ;
	}
	auto average_duration3 = total_duration3 / num;
	std::cout << "Average duration (nanoseconds): " << average_duration3 << std::endl;
	std::cout<<std::endl;
	return 0;
}
